
import { v4 as uuidv4 } from "uuid";
import { toPara } from "@/utils/base";

/**
 *页签栏 
 */
export class TabItemClass {
  /**
   * 唯一标识符
   */
  id: string = "";

  /**
   * 组件名称
   */
  name: string = "";

  /**
   * 标题
   */
  title: string = "无标题";

  /**
   * 是否隐藏关闭按钮
   */
  hiddenClose: boolean = false;

  /**
   * 图标
   */
  icon: string = "";

  /**
   * 当前目录配置文件
   */
  pageComponent: any | null = null

  constructor(para: {
    name: string;
    title: string;
    hiddenClose?: boolean;
    icon?: string;
    pageComponent: any,
  }) {
    this.id = uuidv4();
    this.name = para.name;
    this.title = para.title;
    this.hiddenClose = para.hiddenClose || false;
    this.pageComponent = para.pageComponent;
    if (para.icon) {
      this.icon = para.icon
    } else {
      this.icon = require("@/assets/app/ck.svg")
    }
  }
}

/**
 * 菜单类接口
 */
export interface MenuNodeInterface {
  id: number;
  title: string;
  parentId?: number;
  icon?: string;
  pageName: string;
  vxList?: number[];
  list?: MenuNodeInterface[];
}

/**
 * 菜单类
 */
export class MenuNodeClass {
  /**
   * 当前节点ID
   */
  id: number = 0;

  /**
   * 父级节点id'
   */
  parentId: number = 0;

  /**
   * 对应的tab页签的id
   * 只有打开过的页面会存在
   */
  tabId: string = "";

  /**
   * 名称
   */
  title: string = "";

  /**
   * 图标
   */
  icon: string = "";

  /**
   * 前往页面
   */
  pageName: string = "";

  /**
   * 按钮权限
   */
  actionMap: {
    [key: string]: boolean
  } = {}

  /**
   * 当前页面权限
   */
  vxList: number[] = [];

  /**
   * 子节点信息
   */
  list: MenuNodeClass[] = [];

  constructor(para: MenuNodeInterface) {
    this.id = para.id;
    this.title = para.title;
    if (para.icon) {
      this.icon = para.icon
    } else {
      this.icon = require("@/assets/app/ck.svg")
    }
    if (para.pageName) this.pageName = para.pageName;
    if (para.parentId) this.parentId = para.parentId;
  }
}

/**
 * 组织列表
 */
export class OrgDataClass {
  /**
   * 当前节点Id
   */
  Id: number = 0
  /**
   * 父节点Id
   */
  ParentId: number = 0
  /**
   * 父节点名称
   */
  ParentName: string = ""
  /**
   * 菜单名称
   */
  Name: string = ""
  SortNum: number = 0
  CreatePerson: string = ""
  CreateDate: string = ""
  UpdateDate: string = ""
  UnionGuid: string = ""
  /**
   * 子节点信息
   */
  children: OrgDataClass[] = [];

  constructor(para: any) {
    if (para) {
      //这里子节点单独提起出来进行处理
      toPara(this, Object.assign({}, para, {
        children: []
      }));

      //我们这里走一个递归, 自动把全部子节点进行更新
      if (para.children instanceof Array && para.children.length > 0) {
        for (let item of para.children) {
          this.children.push(new OrgDataClass(item))
        }
      }
    }
  }
}